package com.qf.service;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        //根据用户名查询数据库，获取到我们自己user对象，封装成security的User对象

        return User.withUsername("zs")
                //如果给的是密文，回头要注入密码加密器;如果给的是明文，需要注入一个不加密的密码编码器
                .password(BCrypt.hashpw("123",BCrypt.gensalt()))
                //权限字符串格式 ROLE_XX
                .authorities("ROLE_P1","ROLE_P2")
                //权限字符串格式 XX  不能带ROLE_前缀
//                .roles("P1")
                .build();
    }
}
